import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    isListening: false,
    isProcessing: false,
    conversation: [],
    currentQuery: '',
    currentResponse: '',
    agentStatus: {}
  },
  mutations: {
    SET_LISTENING(state, status) {
      state.isListening = status;
    },
    SET_PROCESSING(state, status) {
      state.isProcessing = status;
    },
    ADD_CONVERSATION(state, { query, response }) {
      state.conversation.push({ query, response, timestamp: new Date() });
    },
    SET_CURRENT_QUERY(state, query) {
      state.currentQuery = query;
    },
    SET_CURRENT_RESPONSE(state, response) {
      state.currentResponse = response;
    },
    UPDATE_AGENT_STATUS(state, { agentName, status }) {
      state.agentStatus = { ...state.agentStatus, [agentName]: status };
    }
  },
  actions: {
    startListening({ commit }) {
      commit('SET_LISTENING', true);
    },
    stopListening({ commit }) {
      commit('SET_LISTENING', false);
    },
    processVoiceInput({ commit }, query) {
      commit('SET_CURRENT_QUERY', query);
      commit('SET_PROCESSING', true);
    },
    receiveResponse({ commit }, response) {
      commit('SET_CURRENT_RESPONSE', response);
      commit('ADD_CONVERSATION', { 
        query: this.state.currentQuery, 
        response 
      });
      commit('SET_PROCESSING', false);
    },
    updateAgentStatus({ commit }, { agentName, status }) {
      commit('UPDATE_AGENT_STATUS', { agentName, status });
    }
  },
  getters: {
    isListening: state => state.isListening,
    isProcessing: state => state.isProcessing,
    conversation: state => state.conversation,
    currentQuery: state => state.currentQuery,
    currentResponse: state => state.currentResponse,
    agentStatus: state => state.agentStatus
  }
}); 